<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Multi_Upload extends CI_Controller
{
	protected $_templates;
	function __construct()
	{
        parent::__construct();
        $this->pre_message = "";
        $this->load->model('image_model','image');
        $this->lang->load('file_image');
	}
	
    public function do_upload()
	{
        $options = array(
            'upload_dir' => '../uploads/temp/',
            'upload_url' => base_url_site().'uploads/temp/');
        $this->load->library('multiupload/UploadHandler',$options);
    }
	
    function create_dir()
	{
        $y_m_dir = date('Y').'/'.date('m');
        $str_dir = '../uploads/images/'.$y_m_dir.'/'; 
        if(!is_dir($str_dir)){
            @mkdir($str_dir,0777, true);
        }
        return $y_m_dir;
    }
	
    public function do_upload_images()
	{
        $options = array(
            'upload_dir' => '../uploads/images/'.$this->create_dir().'/',
            'upload_url' => base_url_site().'uploads/images/'.$this->create_dir().'/',
            'script_url' => base_url().'mod_file_manager/multi_upload/do_upload_action'
		);
        $this->load->library('multiupload/UploadHandler',$options);
    }
	
    public function do_upload_action()
	{
        $file_name = $this->input->get('file');
        $rs = $this->image->getFileByName($file_name);
        if($rs)
		{
            if(unlink('../uploads/images/'.$rs->lb_dir.'/'.$rs->lb_name))
			{
                $this->image->delete($rs->image_data_id);
            }
        }
    }
}
?>
